package 笔试.新凯来;

import java.util.HashMap;
import java.util.Scanner;

// 200
public class 筛选重复字符 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        Solution1 solution1 = new Solution1();
        System.out.println(solution1.findMinTimesCharIndex(line));
        Solution2 solution2 = new Solution2();
        System.out.println(solution2.findMinTimesCharIndex(line));
    }

    static class Solution1 {
        public int findMinTimesCharIndex(String line) {
            HashMap<Character, Integer> timesMap = new HashMap<>();
            HashMap<Character, Integer> indexMap = new HashMap<>();
            for (int i = 0; i < line.length(); i++) {
                char ch = line.charAt(i);
                timesMap.merge(ch, 1, Integer::sum);
                indexMap.putIfAbsent(ch, i);
            }
            int minIndex = -1;
            int minTimes = Integer.MAX_VALUE;
            for (Character ch : timesMap.keySet()) {
                int times = timesMap.get(ch);
                int index = indexMap.get(ch);
                if (times < minTimes) {
                    minTimes = times;
                    minIndex = index;
                } else if (times == minTimes) {
                    minIndex = Math.min(minIndex, index);
                }
            }
            /*
                minTimes = timesMap.entrySet().stream().mapToInt(Map.Entry::getValue).min().orElse(0);
                List<Character> collect = timesMap.entrySet().stream()
                        .filter(o -> o.getValue().equals(minTimes))
                        .map(Map.Entry::getKey)
                        .collect(Collectors.toList());
                minIndex = indexMap.entrySet().stream()
                        .filter(o -> collect.contains(o.getKey()))
                        .sorted(Comparator.comparingInt(Map.Entry::getValue))
                        .map(Map.Entry::getValue)
                        .limit(1)
                        .findFirst().orElse(0);
             */
            return minIndex;
        }
    }

    static class Solution2 {
        public int findMinTimesCharIndex(String line) {
            HashMap<Character, Integer> timesMap = new HashMap<>();
            for (int i = 0; i < line.length(); i++) {
                char ch = line.charAt(i);
                timesMap.merge(ch, 1, Integer::sum);
            }
            int minIndex = -1;
            int minTimes = Integer.MAX_VALUE;
            for (int i = 0; i < line.length(); i++) {
                char ch = line.charAt(i);
                if (timesMap.get(ch) < minTimes) {
                    minTimes = timesMap.get(ch);
                    minIndex = i;
                }
            }
            return minIndex;
        }
    }
}
